//
//  StatusRetweetedCell.swift
//  Weibo
//
//  Created by 李亚乐 on 15/12/14.
//  Copyright © 2015年 李亚乐. All rights reserved.
//

import UIKit

// MARK: - 自定义 cell
/// 转发微博 Cell
class StatusRetweetedCell: StatusCell {
    
    /// 转发微博的视图模型
    override var viewModel: StatusViewModel?{
        didSet {
            //给子控件赋值
            retweetedText.text = viewModel?.retweetedText
            
            picView.snp_updateConstraints { (make) -> Void in
                
                // 根据配图数量，决定配图视图的顶部间距
                let offset = viewModel?.thumbnailURLs?.count > 0 ? StatusCellMargin : 0
                make.top.equalTo(retweetedText.snp_bottom).offset(offset)
            }
        }
    }
    
    
    // MARK: - 懒加载子控件
    /// 背景按钮
    private lazy var backgroundButton: UIButton = {
        let button = UIButton()
        
        button.backgroundColor = UIColor(white: 0.95, alpha: 1.0)
        
        return button
    }()
    
    private lazy var retweetedText: UILabel = UILabel(title: "转发微博", screenInset: StatusCellMargin)
    
    
    override func setupUI() {
/// super
        super.setupUI()
/// 添加子控件
        contentView.insertSubview(backgroundButton, belowSubview: picView)
        contentView.insertSubview(retweetedText, aboveSubview: backgroundButton)
        
        backgroundButton.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(textView.snp_bottom).offset(StatusCellMargin)
            make.left.equalTo(contentView.snp_left)
            make.bottom.equalTo(bottomView.snp_top)
            make.right.equalTo(contentView.snp_right)
        }
        
        retweetedText.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(backgroundButton.snp_top).offset(StatusCellMargin)
            make.left.equalTo(backgroundButton.snp_left).offset(StatusCellMargin)
        }
        
        picView.snp_makeConstraints(closure: { (make) -> Void in
            make.left.equalTo(retweetedText.snp_left)
            make.top.equalTo(retweetedText.snp_bottom).offset(StatusCellMargin)
            make.width.equalTo(300)
            make.height.equalTo(90)
        })

    }
}
